<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 反馈模型
 *
 * @author www.dingwei.cn
 */

class DlnFeedbackModel extends MY_Model{
	
	public $tbFeedback = 'deliveryman_feedback';
	
	/**
	 * 获取状态显示样式
	 * @param 	integer $status
	 * @return	string
	 */
	public function status($status = null, $show = false){
	
		$config = [1 => '未处理', 2 => '已回复'];
		if( ! $status){
			return $config;
		}
	
		if($status && ! isset($config[$status])){
			return '';
		}
	
		if( ! $show){
			return $config[$status];
		}
	
		if($status == 1){
			return '<span class="label label-danger status">'.$config[$status].'</span>';
		}elseif($status == 2){
			return '<span class="label label-success status">'.$config[$status].'</span>';
		}
	
		return'';
	}

    /**
     * 获取未处理的意见反馈数量
     * @return array
     */
    public function getFeedbackCount($county = array()){
        if($county){
            get_instance()->loadModel('DlnUserModel', 'mDlnUser', 'deliveryman');
            $this->db->join($this->mDlnUser->tbUser. ' s', 's.id = f.deliveryman_id')
                ->where_in('s.county_id', $county);
        }
        $this->db->select('count(f.id) as total')
                ->where('f.status', 1);

        return $this->getOne($this->tbFeedback.' f');
    }
}